//
//  NoteRemote.swift
//  MyNoteDemo4
//
//  Created by BZF on 2020/8/24.
//  Copyright © 2020 bzf. All rights reserved.
//

import Foundation
import Alamofire

public class NoteRemote{
    
    private let strURL = "http://www.51work6.com/service/mynotes/WebService.php"
    
    //插入一条数据到服务端
    public func insert(_ mode: Note, handler: @escaping (AFDataResponse<Any>) -> Void) {
        let dateFormatter: DateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        let strDate = dateFormatter.string(from: mode.date as Date)
        
        let params = ["email": "709889312@qq.com", "type": "JSON", "action": "add", "date": strDate, "content": mode.content]
        AF.request(strURL, method: HTTPMethod.post, parameters: params).responseJSON(completionHandler: handler)
    }
    
    
    public func getAll(handler: @escaping (AFDataResponse<Any>) -> Void) {
        
        let params = ["email": "709889312@qq.com", "type": "JSON", "action": "query"]
        let response  =  AF.request(strURL, method: HTTPMethod.post,parameters: params).responseJSON(queue: DispatchQueue.global(qos: .background)
            ,completionHandler: handler)
         
    }
    
}
